<template>
  <div class="app-container">
<!--    <div class="dashboard-editor-container">
      <panel-group @handleSetLineChartData="handleSetLineChartData" />
      <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
        <line-chart :chart-data="lineChartData" />
      </el-row>
      <el-row :gutter="32">
        <el-col :xs="24" :sm="24" :lg="8">
          <div class="chart-wrapper">
            <raddar-chart />
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="8">
          <div class="chart-wrapper">
            <pie-chart />
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="8">
          <div class="chart-wrapper">
            <bar-chart />
          </div>
        </el-col>
      </el-row>
    </div>-->
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
<!--      <el-form-item label="基金名称" prop="ipaddr">
        <el-input
          v-model="queryParams.ipaddr"
          placeholder="请输入基金名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基金编码" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入基金编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

    </el-form>
  <!-- //'序号', '基金名称（代码）', '今日涨幅(%)', '买入份额', '买入金额', '今日收益', '持有收益额', '持有收益率', '昨日净值', '今日估算值   -->
    <el-table
      v-loading="loading"
      style="width: 100%;"
      :default-sort="defaultSort" @sort-change="handleSortChange"
      :data="list.filter(data => !search || data.code.toLowerCase().includes(search.toLowerCase()))"
      :fit="true"
    >
      <el-table-column label="序号" type="index" align="center" fixed>
        <template slot-scope="scope">
          <span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="id" align="center" prop="id" :show-overflow-tooltip="true"  hidden="hidden"/>
      <el-table-column label="基金名称" align="center" prop="code" :show-overflow-tooltip="true"  fixed sortable/>
      <el-table-column label="买入金额" align="center" prop="purchasePrice" :show-overflow-tooltip="true" sortable/>
      <el-table-column label="持有金额" align="center" prop="holdPrice" sortable/>
      <el-table-column label="成本价" align="center" prop="basePrice" sortable/>
      <el-table-column label="净值" align="center" prop="yjz" :show-overflow-tooltip="true" sortable/>
      <el-table-column label="估算值" align="center" prop="gsz" :show-overflow-tooltip="true" sortable/>
      <el-table-column label="涨幅(%)" align="center" prop="zd" sortable/>
      <el-table-column label="今日收益" align="center" prop="todayProfit" sortable/>
      <el-table-column label="收益率" align="center" prop="holdRate" width="180" sortable/>
      <el-table-column  align="center" prop="upDateTime" width="180" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.upDateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column  align="right" width="300">
        <template slot="header" slot-scope="scope">
          <el-input
            v-model="search"
            size="mini"
            placeholder="输入关键字搜索"/>
        </template>
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-tickets"
            @click="fundDetail(scope.row)"
            v-hasPermi="['monitor:online:forceLogout']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleForceLogout(scope.row)"
            v-hasPermi="['monitor:online:forceLogout']"
          >编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" />
  </div>
</template>

<script>
import PanelGroup from '../../dashboard/PanelGroup'
import LineChart from '../../dashboard/LineChart'
import RaddarChart from '../../dashboard/RaddarChart'
import PieChart from '../../dashboard/PieChart'
import BarChart from '../../dashboard/BarChart'
import { forceLogout, list } from '@/api/monitor/online'

const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'Statistics',
  components: {
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      dialogOpen:false,
      lineChartData: lineChartData.newVisitis,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      pageNum: 1,
      pageSize: 10,
      // 查询参数
      queryParams: {
        ipaddr: undefined,
        userName: undefined
      },
      // 默认排序
      defaultSort: {prop: 'updateTime', order: 'descending'},
      search:""
    }
  },
  created() {
    this.getList();
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    },
    /** 查询登录日志列表 */
    getList() {
      this.list = [{
        id:0,
        code:"农银医疗（000913）",
        purchasePrice:1.3,
        holdPrice:1000,
        basePrice:1.0,
        yjz:1.3,
        gsz:100,
        zd:0.2,
        todayProfit:300,
        holdRate:0.2,
        upDateTime:'2021-08-13 15:00:00'

    },{
        id:1,
        code:"招商白酒（000913）",
        purchasePrice:1.3,
        holdPrice:1000,
        basePrice:1.0,
        yjz:1.3,
        gsz:200,
        zd:0.2,
        todayProfit:300,
        holdRate:0.3,
        upDateTime:'2021-08-13 15:00:00'

      }];
      this.total = 0;
      this.loading = false;
      /*this.loading = true;
      list(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });*/
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 强退按钮操作 */
    handleForceLogout(row) {
      this.$confirm('是否确认强退名称为"' + row.userName + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return forceLogout(row.tokenId);
      }).then(() => {
        this.getList();
        this.msgSuccess("强退成功");
      }).catch(() => {});
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
